home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
himath.zip
/
MATHDEMO.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-10-04
|
25KB
|
639 lines
'***************************************************************************
'**** MATHDEMO.BAS Test Kevin Jorgensen's "HIMATH" Library
'***************************************************************************
DEFDBL A-Z
CONST Pi = 3.141592653589793#
CONST HalfPi = Pi / 2#
CONST TwoPi = Pi * 2#
TYPE VRect 'User type for 3d Vector Math
x AS DOUBLE
y AS DOUBLE
z AS DOUBLE
END TYPE
TYPE XRect 'User Type for Complex Numbers
i AS DOUBLE
j AS DOUBLE
END TYPE
'======================================================================
'Math Demo Routines
'======================================================================
DECLARE SUB TestHold ()
DECLARE SUB TestMatrix1 ()
DECLARE SUB TestMatrix2 ()
DECLARE SUB TestMatrixLoad (GivenMtx#(), A$)
DECLARE SUB TestMatrixPrint (MtxErr%, Mtx())
DECLARE SUB TestInvTrig ()
DECLARE SUB TestTriangle ()
DECLARE SUB TestTriangle2 (s$, p1#, p2#, p3#)
DECLARE SUB TestVector ()
DECLARE SUB TestVectorLoad (GivenVctr AS ANY, A$)
DECLARE SUB TestVectorPrint (GivenVctr AS ANY)
DECLARE SUB TestXmath ()
DECLARE SUB TestXMatrix1 ()
DECLARE SUB TestXMatrix2 ()
DECLARE SUB TestXMatrixLoad (GivenMtx() AS XRect, A$)
DECLARE SUB TestXMatrixPrint (MtxErr%, Mtx() AS XRect)
'======================================================================
'======================================================================
'Demo'd in TestInvTrig
DECLARE FUNCTION ACOS (x)
DECLARE FUNCTION ASIN (y)
DECLARE FUNCTION ATAN2 (x, y)
'Demo'd in TestTriangle
DECLARE SUB TriangleSolve (ProbType$, p1, p2, p3, A(), s(), NbrOfSolutions%)
'Demo'd in TestMatrix1
DECLARE SUB MtxCoeff (MtxErr%, Mtx(), Vctr(), Coeff())
DECLARE SUB MtxCoeffA (MtxErr%, Mtx())
DECLARE SUB MtxCopy (MtxErr%, Src(), Dst())
DECLARE FUNCTION MtxDet (MtxErr%, Mtx())
'Demo'd in TestMatrix2
DECLARE SUB MtxAdd (MtxErr%, A(), B(), C())
DECLARE SUB MtxSub (MtxErr%, A(), B(), C())
DECLARE SUB MtxInv (MtxErr%, A(), B())
DECLARE SUB MtxMltS (MtxErr%, A(), B, C())
DECLARE SUB MtxMltX (MtxErr%, A(), B(), C())
'Demo'd in TestXmath
DECLARE SUB XCnvP (r, t, Result AS XRect)
DECLARE SUB XCnvR (i, j, Result AS XRect)
DECLARE FUNCTION XMag (Op1 AS XRect)
DECLARE FUNCTION XAng (Op1 AS XRect)
DECLARE FUNCTION XReal (Op1 AS XRect)
DECLARE FUNCTION XImag (Op1 AS XRect)
DECLARE FUNCTION XFmtP$ (Op1 AS XRect)
DECLARE FUNCTION XFmtR$ (Op1 AS XRect)
DECLARE SUB XAdd (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XSub (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XMlt (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XDiv (Op1 AS XRect, Op2 AS XRect, Result AS XRect)
DECLARE SUB XPwr (Op1 AS XRect, Op2, Result AS XRect)
DECLARE SUB XCnj (Op1 AS XRect, Result AS XRect)
DECLARE SUB XInv (Op1 AS XRect, Result AS XRect)
'Demo'd in TestXMatrix1
DECLARE SUB XMtxCoeff (MtxErr%, Mtx() AS XRect, Vctr() AS XRect, Coeff() AS XRect)
DECLARE SUB XMtxCoeffA (MtxErr%, Mtx() AS XRect)
DECLARE SUB XMtxCopy (MtxErr%, Src() AS XRect, Dst() AS XRect)
DECLARE SUB XMtxDet (MtxErr%, XMtx() AS XRect)
'Demo'd in TestXMatrix2
DECLARE SUB XMtxAdd (MtxErr%, A() AS XRect, B() AS XRect, C() AS XRect)
DECLARE SUB XMtxInv (MtxErr%, A() AS XRect, Mtx() AS XRect)
DECLARE SUB XMtxMltS (MtxErr%, A() AS XRect, B AS XRect, C() AS XRect)
DECLARE SUB XMtxMltX (MtxErr%, A() AS XRect, B() AS XRect, C() AS XRect)
DECLARE SUB XMtxSub (MtxErr%, A() AS XRect, B() AS XRect, C() AS XRect)
'Demo'd in TestVector
DECLARE SUB VAdd (Op1 AS VRect, Op2 AS VRect, Result AS VRect)
DECLARE SUB VMltX (Op1 AS VRect, Op2 AS VRect, Result AS VRect)
DECLARE SUB VSub (Op1 AS VRect, Op2 AS VRect, Result AS VRect)
DECLARE FUNCTION VMltD (Op1 AS VRect, Op2 AS VRect)
'======================================================================
RANDOMIZE TIMER
TestInvTrig
TestTriangle
TestMatrix1
TestMatrix2
TestXmath
TestXMatrix1
TestXMatrix2
TestVector
END
'======================================================================
SUB TestHold
'======================================================================
PRINT "Press Enter to Continue ";
x = CSRLIN
DO
LOOP UNTIL INKEY$ <> ""
LOCATE x, 1: PRINT SPACE$(40)
END SUB
'======================================================================
SUB TestInvTrig
'======================================================================
CLS
PRINT "SUB TestInvTrig Demonstrating of ASIN, ACOS, and ATAN functions"
PRINT
PRINT "Given --------------------------- Calc'd -------------------"
PRINT "ang SIN COS TAN ASIN ACOS ATAN"
PRINT "--- ------- ------- ------------ -------- -------- --------"
FOR x = 0 TO 360 STEP 30
t = x / 180 * Pi
xsin = SIN(t)
xcos = COS(t)
xtan = TAN(t)
ysin = ASIN(xsin) * 180# / Pi
ycos = ACOS(xcos) * 180# / Pi
ytan = ATAN2(xcos, xsin) * 180# / Pi
IF ABS(xtan) >= 0 AND ABS(xtan) < 99999 THEN
PRINT USING "### ##.#### ##.#### #####.###### ####.### ####.### ####.###"; x; xsin; xcos; xtan; ysin; ycos; ytan
ELSE
PRINT USING "### ##.#### ##.#### ##.#####^^^^ ####.### ####.### ####.###"; x; xsin; xcos; xtan; ysin; ycos; ytan
END IF
NEXT x
TestHold
END SUB
'======================================================================
SUB TestMatrix1
'======================================================================
Rows% = 8: ColVctr% = Rows% + 1
DIM ScratchMtx(Rows%, ColVctr%), GivenMtx(Rows%, ColVctr%)
DIM ScratchMtx2(Rows%, Rows%), Vctr(Rows%), Coeff(Rows%)
CLS
PRINT "SUB TestMatrix1 Demonstrating MtxCoeff, MtxCoeffA, MtxCopy, MtxDet"
TestMatrixLoad GivenMtx(), "A"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Determinant using MtxDet ═════════════════════════════════════"
MtxCopy MtxErr%, GivenMtx(), ScratchMtx()
PRINT "║ Determinant = "; MtxDet(MtxErr%, ScratchMtx())
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Coefficients using MtxCoeffA ═════════════════════════════════"
'The Column Vector Must be in the last colum of the array
'ie. if the matrix is 5x5, the colum vector should be in column 6
MtxCopy MtxErr%, GivenMtx(), ScratchMtx()
MtxCoeffA MtxErr%, ScratchMtx()
'TestMatrixPrint MtxErr%, ScratchMtx()
PRINT "║";
FOR i% = 1 TO Rows%
PRINT USING " ##.####"; ScratchMtx(i%, ColVctr%);
NEXT i%
PRINT
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
'***************************************************************************
'***************************************************************************
PRINT "╔══ Calculate Coefficients using MtxCoeff ═════════════════════════════════"
FOR i% = 1 TO Rows%
Vctr(i%) = GivenMtx(i%, ColVctr%)
NEXT i%
MtxCopy MtxErr%, GivenMtx(), ScratchMtx2()
MtxCoeff MtxErr%, ScratchMtx2(), Vctr(), Coeff()
PRINT "║";
FOR i% = 1 TO Rows%
PRINT USING " ##.####"; Coeff(i%);
NEXT i%
PRINT
PRINT "╚═══════════════════════════════════════════════════════════════════════════"
TestHold
END SUB
'======================================================================
SUB TestMatrix2
'======================================================================
DIM MtxA(3, 3), MtxB(3, 3), MtxC(3, 3)
'======================================================================
CLS
PRINT "SUB TestMatrix2 Demonstrating MtxAdd"
TestMatrixLoad MtxA(), "A"
TestMatrixLoad MtxB(), "B"
MtxAdd Merr%, MtxA(), MtxB(), MtxC()
PRINT "╔══ Calculate Sum of two Matrices using MtxAdd ═════════════════════════════"
TestMatrixPrint Merr%, MtxC()
PRINT "╚═════════